//
//  DHNewsDetail_CommentCell.m
//  Dresshere
//
//  Created by ZhangPeng on 2018/5/28.
//  Copyright © 2018年 张朋. All rights reserved.
//

#import "DHNewsDetail_CommentCell.h"
#import "DHArticleCommentCell.h"
#import "DHArticleNO_CommentCell.h"
#import "DHCommentListViewController.h"

@interface DHNewsDetail_CommentCell()<UITableViewDelegate, UITableViewDataSource>

@property (strong, nonatomic) NSArray *arr; //数据
@property (weak, nonatomic) IBOutlet UIButton *checkAllCommentButton;

@end

@implementation DHNewsDetail_CommentCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerNib:[UINib nibWithNibName:@"DHArticleCommentCell" bundle:nil] forCellReuseIdentifier:kDHArticleCommentCell];
    [self.tableView registerNib:[UINib nibWithNibName:@"DHArticleNO_CommentCell" bundle:nil] forCellReuseIdentifier:kDHArticleNO_CommentCell];
    
    WeakSelf(weakSelf)
    [self.checkAllCommentButton bk_addEventHandler:^(id sender) {
        DHCommentListViewController *vc = [[DHCommentListViewController alloc] initWithArticleID:self.articleID];
        [weakSelf.viewController.navigationController pushViewController:vc animated:YES];
    } forControlEvents:UIControlEventTouchUpInside];
    
}

- (NSArray *)arr{
    if (!_arr) {
        _arr = [NSArray array];
    }
    return _arr;
}

- (void)updateCellArr:(NSArray *)arr{
    self.arr = arr;
    [self.tableView reloadData];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

#pragma mark - UITableViewDataSource and UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (self.arr.count > 0) {
        return self.arr.count;
    }else{
        return 1;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.arr.count > 0) {
        return 147;
    }else{
        return 40;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.arr.count > 0) {
        DHArticleCommentCell *cell = [tableView dequeueReusableCellWithIdentifier:kDHArticleCommentCell forIndexPath:indexPath];
        NSDictionary *dic = self.arr[indexPath.row];
        [cell updateWithDic:dic];
        cell.isCommunityComment = self.isCommunityComment;
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        return cell;
    }else{
        DHArticleNO_CommentCell *cell = [tableView dequeueReusableCellWithIdentifier:kDHArticleNO_CommentCell forIndexPath:indexPath];
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        return cell;
    }
}

@end
